package com.lam.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lam.common.base.controller.BaseController;
import com.lam.common.base.domain.Result;
import com.lam.common.components.dict.annotation.DictAutoTransfer;
import com.lam.common.components.easyexcel.export.DownloadUtil;
import com.lam.framework.annotation.ParamInject;
import com.lam.framework.bean.entity.SysFile;
import com.lam.framework.operLog.annotation.Log;
import com.lam.framework.operLog.enums.BusinessType;
import com.lam.system.param.SysFileParam;
import com.lam.system.service.SysFileService;

/**
 * 文件记录Controller
 * 
 * @author admin
 * @date 2022-10-08
 */
@Log(title = "文件记录")
@ParamInject
@RestController
@RequestMapping("/${adminPath}/sys/file")
public class SysFileController extends BaseController {

    @Autowired
    private SysFileService sysFileService;

    /**
     * 查询文件记录列表
     */
    @Log(oper="分页查询")
    @DictAutoTransfer
    @PreAuthorize("@ss.hasPm('sys:file:list')")
    @GetMapping("/list")
    public Result list(SysFileParam param) {
    
        startPage();
        List<SysFile> list = sysFileService.selectList(param);
        return Result.ok(getTableData(list));
    }
    
    /**
     * 导出文件记录列表
     */
    @PreAuthorize("@ss.hasPm('sys:file:export')")
    @Log(businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public Result export(SysFileParam param) {
    
        withOrderBy();
        List<SysFile> list = sysFileService.selectList(param);
        return Result.ok(DownloadUtil.exportExcel("文件记录导出", list, SysFile.class));
    }
    
    /**
     * 获取文件记录详细信息
     */
    @DictAutoTransfer
    @Log(oper="根据ID查询")
    @PreAuthorize("@ss.hasPm('sys:file:query')")
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable("id") String id) {
    
        return Result.ok(sysFileService.selectById(id));
    }
    
    /**
     * 删除文件记录
     */
    @PreAuthorize("@ss.hasPm('sys:file:remove')")
    @Log(businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable String id) {
    
        return toAjax(sysFileService.deleteById(id));
    }
    

}
